function BSInputHandler(input, __shell)
{
    var _input      = input;
    var _shell      = __shell;
    var myself      = this;
    var _history    = new Array();
    var historySelectedPosition = -1;



    this.setInput = function(command)
    {
        if(_input.value!= undefined) {
            _input.value = command;
        } else if(_input.text != undefined) {
           _input.text = command;
        }
    }

    this.clearInput = function()
    {
        if(_input.value) {
            _input.value = "";
        }
        if(_input.text) {
           _input.text = "";
        }
    }

    _input.onkeyup = function(e)
    {
        e = e || window.event;
        if(e.keyCode == 38) {
            if(historySelectedPosition < _history.length-1) {
                historySelectedPosition++;
                myself.setInput(_history[_history.length - historySelectedPosition - 1]);
            }
        }

        if (e.keyCode == 40) {
            if (historySelectedPosition > 0) {
                historySelectedPosition--;
                myself.setInput(_history[_history.length - historySelectedPosition - 1]);
            } else {
                myself.setInput("");
            }
        }

        if (e.keyCode == 13) {
            var command = getCommand();
            _history.push(command);
            historySelectedPosition = -1;
            _shell.exec(command);
            myself.clearInput();
        }
    }

    var getCommand = function()
    {
        if(_input.value) {
            return _input.value;
        }
        if(_input.text) {
            return _input.text;
        }
        return "";
    }
}
